package com.example.sample.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.example.app.BaseActivity;
import com.example.sample.R;

import net.liteheaven.xblib.common.ui.ToastUtil;

/**
 * Created by liangy on 2016/12/15.
 */
public class MethodReborn2Activity extends BaseActivity {

    private Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_method_reborn);
        btn = (Button)findViewById(R.id.btn);
        btn.setText("检查参数");

        final MethodRebornActivity.PerformOnClick callback = (MethodRebornActivity.PerformOnClick)getIntent().getSerializableExtra("callback");
        final MethodRebornActivity.MyRunnable runnable = callback.runnable;
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                runnable.show(MethodReborn2Activity.this);
            }
        });

        initArgs(savedInstanceState);
    }

    private void initArgs(Bundle savedInstanceState){
        Bundle bundle = null;
        if (savedInstanceState != null){
            bundle = savedInstanceState;
        }else{
            Intent intent = getIntent();
            if (intent != null){
                bundle = getIntent().getExtras();
            }
        }
        String arg = bundle != null ? bundle.getString("tag") : "无参数";
        ToastUtil.show(this, arg);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        //outState.putAll(getIntent().getExtras());
    }
}
